package com.intelli.eve.core.impl.system_info;

import com.intelli.ray.core.ManagedComponent;

import java.io.File;

/**
 * Author: Sergey42
 * Date: 27.12.2014 14:00
 */
@ManagedComponent(name = SystemInfo.NAME)
public class SystemInfoProvider implements SystemInfo {

    @Override
    public String getOS() {
        return getSystemProperty("os.name");
    }

    @Override
    public String getOSVersion() {
        return getSystemProperty("os.version");
    }

    @Override
    public String getOSArch() {
        return getSystemProperty("os.arch");
    }

    @Override
    public String getSystemProperty(String key) {
        return System.getProperty(key);
    }

    @Override
    public int getAvailableProcessors() {
        return Runtime.getRuntime().availableProcessors();
    }

    @Override
    public long getFreeMemory() {
        return Runtime.getRuntime().freeMemory();
    }

    @Override
    public long getTotalMemory() {
        return Runtime.getRuntime().totalMemory();
    }

    @Override
    public long getFreeSpaceMb(String disk) {
        File file = new File(disk);
        long freeSpace = file.getFreeSpace();
        return freeSpace >> 20;
    }

    @Override
    public long getTotalSpaceMb(String disk) {
        File file = new File(disk);
        long totalSpace = file.getTotalSpace();
        return totalSpace >> 20;
    }

    @Override
    public String getSystemProperties() {
        return System.getProperties().toString();
    }
}
